home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / gdb.new / gdb-3.98 / bfd.mips / icoff.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-23  |  6.0 KB  |  204 lines

  1. /* Intel 960 COFF support for BFD.
  2.    Copyright (C) 1990-1991 Free Software Foundation, Inc.
  3.    Written by Cygnus Support.
  4.  
  5. This file is part of BFD, the Binary File Descriptor library.
  6.  
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2 of the License, or
  10. (at your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program; if not, write to the Free Software
  19. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  20.  
  21. /* $Id: icoff.c,v 1.18 1991/07/31 16:57:41 gnu Exp $ */
  22.  
  23. #define I960 1
  24. #define BADMAG(x) I960BADMAG(x)
  25.  
  26. #include <ansidecl.h>
  27. #include <sysdep.h>
  28. #include "bfd.h"
  29. #include "libbfd.h"
  30. #include "obstack.h"
  31. #include "intel-coff.h"
  32. #include "internalcoff.h"
  33. #include "libcoff.h"        /* to allow easier abstraction-breaking */
  34.  
  35.  
  36. #define CALLS     0x66003800    /* Template for 'calls' instruction    */
  37. #define BAL     0x0b000000    /* Template for 'bal' instruction    */
  38. #define BAL_MASK 0x00ffffff
  39.  
  40. static bfd_reloc_status_enum_type 
  41. optcall_callback(abfd, reloc_entry, symbol_in, data, ignore_input_section)
  42. bfd *abfd;
  43. arelent *reloc_entry;
  44. asymbol *symbol_in;
  45. unsigned char *data;
  46. asection *ignore_input_section;
  47. {
  48.   /* This item has already been relocated correctly, but we may be
  49.    * able to patch in yet better code - done by digging out the
  50.    * correct info on this symbol */
  51.   bfd_reloc_status_enum_type result;
  52.   coff_symbol_type *cs = coffsymbol(symbol_in);
  53.  
  54.   /* So the target symbol has to be of coff type, and the symbol 
  55.      has to have the correct native information within it */
  56.   if ((cs->symbol.the_bfd->xvec->flavour != bfd_target_coff_flavour_enum)
  57.       || (cs->native == (combined_entry_type *)NULL)) {
  58.      /* This is interesting, consider the case where we're outputting */
  59.      /* coff from a mix n match input, linking from coff to a symbol */
  60.      /* defined in a bout file will cause this match to be true. Should */
  61.      /* I complain ? - This will only work if the bout symbol is non */
  62.      /* leaf. */
  63.      result = bfd_reloc_dangerous;
  64.   }
  65.   else  {
  66.     switch (cs->native->u.syment.n_sclass) 
  67.       {
  68.       case C_LEAFSTAT:
  69.       case C_LEAFEXT:
  70.       /* This is a call to a leaf procedure, replace instruction with a bal
  71.      to the correct location */
  72.     {
  73.       union internal_auxent *aux = &((cs->native+2)->u.auxent);
  74.       int word = bfd_get_32(abfd, data + reloc_entry->address);
  75.       int olf = (aux->x_bal.x_balntry - cs->native->u.syment.n_value);
  76.       BFD_ASSERT(cs->native->u.syment.n_numaux==2);
  77.       /* We replace the original call instruction with a bal to */
  78.       /* the bal entry point - the offset of which is described in the */
  79.       /* 2nd auxent of the original symbol. We keep the native sym and */
  80.       /* auxents untouched, so the delta between the two is the */
  81.       /* offset of the bal entry point */
  82.  
  83.       word = ((word +  olf)  & BAL_MASK) | BAL;
  84.         bfd_put_32(abfd, word,  data+reloc_entry->address);
  85.       }
  86.     result = bfd_reloc_ok;
  87.     break;
  88.       case C_SCALL:
  89.     {
  90.       /* This is a call to a system call, replace with a calls to # */
  91.       BFD_ASSERT(0);
  92.     }
  93.     break;
  94.       default:
  95.     result = bfd_reloc_ok;
  96.     break;
  97.       }
  98.   }
  99.   return result;
  100. }
  101.  
  102.  
  103.  
  104. static reloc_howto_type howto_table[] = 
  105. {
  106.   {0},
  107.   {1},
  108.   {2},
  109.   {3},
  110.   {4},
  111.   {5},
  112.   {6},
  113.   {7},
  114.   {8},
  115.   {9},
  116.   {10},
  117.   {11},
  118.   {12},
  119.   {13},
  120.   {14},
  121.   {15},
  122.   {16},
  123.  
  124.   { (unsigned int) R_RELLONG, 0, 2, 32,false, 0, true, true,
  125.       0,"rellong", true, 0xffffffff, 0xffffffff},
  126.   {18},
  127.   {19},
  128.   {20},
  129.   {21},
  130.   {22},
  131.   {23},
  132.   {24},
  133.  
  134.   {  R_IPRMED, 0, 2, 24,true,0, true, true,0,"iprmed ", true,
  135.        0x00ffffff, 0x00ffffff},
  136.   {26},
  137.  
  138.   {  R_OPTCALL, 0,2,24,true,0, true, true, optcall_callback,
  139.        "optcall", true, 0x00ffffff, 0x00ffffff},
  140.  
  141. };
  142.  
  143. /* The real code is in coffcode.h */
  144.  
  145. #include "coffcode.h"
  146.  
  147. bfd_target icoff_little_vec =
  148. {
  149.   "coff-Intel-little",        /* name */
  150.   bfd_target_coff_flavour_enum,
  151.   false,            /* data byte order is little */
  152.   false,            /* header byte order is little */
  153.  
  154.   (HAS_RELOC | EXEC_P |        /* object flags */
  155.    HAS_LINENO | HAS_DEBUG |
  156.    HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT),
  157.  
  158.   (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
  159.   '/',                /* ar_pad_char */
  160.   15,                /* ar_max_namelen */
  161.  
  162.      3,                /* minimum alignment power */
  163.   _do_getl64, _do_putl64, _do_getl32, _do_putl32, _do_getl16, _do_putl16, /* data */
  164.   _do_getl64, _do_putl64, _do_getl32, _do_putl32, _do_getl16, _do_putl16, /* hdrs */
  165.  
  166.     {_bfd_dummy_target, coff_object_p, /* bfd_check_format */
  167.        bfd_generic_archive_p, _bfd_dummy_target},
  168.     {bfd_false, coff_mkobject,    /* bfd_set_format */
  169.        _bfd_generic_mkarchive, bfd_false},
  170.     {bfd_false, coff_write_object_contents, /* bfd_write_contents */
  171.        _bfd_write_archive_contents, bfd_false},
  172.   JUMP_TABLE(coff)
  173.   };
  174.  
  175.  
  176. bfd_target icoff_big_vec =
  177. {
  178.   "coff-Intel-big",        /* name */
  179.   bfd_target_coff_flavour_enum,
  180.   false,            /* data byte order is little */
  181.   true,                /* header byte order is big */
  182.  
  183.   (HAS_RELOC | EXEC_P |        /* object flags */
  184.    HAS_LINENO | HAS_DEBUG |
  185.    HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT),
  186.  
  187.   (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
  188.   '/',                /* ar_pad_char */
  189.   15,                /* ar_max_namelen */
  190.  
  191.   3,                /* minimum alignment power */
  192. _do_getl64, _do_putl64,  _do_getl32, _do_putl32, _do_getl16, _do_putl16, /* data */
  193. _do_getb64, _do_putb64,  _do_getb32, _do_putb32, _do_getb16, _do_putb16, /* hdrs */
  194.  
  195.   {_bfd_dummy_target, coff_object_p, /* bfd_check_format */
  196.      bfd_generic_archive_p, _bfd_dummy_target},
  197.   {bfd_false, coff_mkobject,    /* bfd_set_format */
  198.      _bfd_generic_mkarchive, bfd_false},
  199.   {bfd_false, coff_write_object_contents,    /* bfd_write_contents */
  200.      _bfd_write_archive_contents, bfd_false},
  201.   JUMP_TABLE(coff),
  202. COFF_SWAP_TABLE
  203. };
  204.